/**********************************************
FileName	:	"CCreditsState.h"

Author Name	:	Ted Pereira (TP)

Purpose		:	Rolls the credits
***********************************************/
#include "CCredits.h"
#include "../Core/CGame.h"
#include "CMainMenuState.h"
#include "../Visual/VIN_BitMapFont.h"
#include "../Managers/InputManager.h"


CCreditsState::CCreditsState()
{
	startPos = 0;
	imageID = -1;
}

CCreditsState::~CCreditsState()
{

}


void CCreditsState::Enter(void)
{
	startPos = 600;
	trigger = false;
	timer = 0.0f;
	background = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/scroll.png");
	back = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/background.png");
	castle = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/castle.png");
	imageID = CSGD_TextureManager::GetInstance()->LoadTexture("resources/Graphics/TunderCatz Logo.png");
	VIN_SoundManager::GetInstance()->PlayBGM(BGM_CREDITS);
}
void CCreditsState::Update(float fElapsedTime)
{
	startPos -= 50 * fElapsedTime;
	if(trigger)
		timer += fElapsedTime;
}

bool CCreditsState::Input(void)
{
	if(InputManager::GetInstance()->Escape())
	{
		CGame::GetInstance()->ChangeState(CMainMenuState::GetInstance());
		CMainMenuState::GetInstance()->main_scrolling = true;
	}
	return true;
}



void CCreditsState::Render(void)
{
	int pluser = 1;
	CSGD_Direct3D* p = CSGD_Direct3D::GetInstance();
	VIN_BitMapFont* b = VIN_BitMapFont::GetInstance();

	CSGD_TextureManager::GetInstance()->Draw(back, 0, 0);
	CSGD_TextureManager::GetInstance()->Draw(castle, 530,160, 1.5f, 1.5f);
	CSGD_TextureManager::GetInstance()->Draw(background, 0, -1800, 2.0f, 2.0f );

	p->Clear();
	b->Render("Created By:",350,(int)startPos +25 * pluser++,1.5,D3DCOLOR_XRGB(0,0,0),GAMEFONT);
	b->Render("TunderCatz",350,(int)startPos +30 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);

	b->Render("Executive Producer:",350,(int)startPos +50 * pluser++,1.5,D3DCOLOR_XRGB(0,0,0),GAMEFONT);
	b->Render("John O'Leske",350,(int)startPos +50 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);

	b->Render("Associate Producer:",350,(int)startPos +50 * pluser++,1.5,D3DCOLOR_XRGB(0,0,0),GAMEFONT);
	b->Render("Ron Powell",350,(int)startPos +50 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);

	b->Render("Team Members:",350,(int)startPos +60 * pluser++,1.5,D3DCOLOR_XRGB(0,0,0),GAMEFONT);
	b->Render("Lane Shapiro",350,(int)startPos +60 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	b->Render("Joe LaBella",350,(int)startPos +60 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	b->Render("Jayson Wu",350,(int)startPos +60 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	b->Render("Ted Pereira",350,(int)startPos +60 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);

	b->Render("Gameplay Engineer:",350,(int)startPos +65 * pluser++,1.5,D3DCOLOR_XRGB(0,0,0),GAMEFONT);
	b->Render("Lane Shapiro",350,(int)startPos +65 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	b->Render("Jayson Wu",350,(int)startPos +65 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);

	b->Render("AI:",350,(int)startPos +70 * pluser++,1.5,D3DCOLOR_XRGB(0,0,0),GAMEFONT);
	b->Render("Lane Shapiro",350,(int)startPos +70 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	b->Render("Joe LaBella",350,(int)startPos +70 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);

	b->Render("Sound Design:",350,(int)startPos +75 * pluser++,1.5,D3DCOLOR_XRGB(0,0,0),GAMEFONT);
	b->Render("Joe LaBella",350,(int)startPos +75 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	
	b->Render("Animations:",350,(int)startPos +80 * pluser++,1.5,D3DCOLOR_XRGB(0,0,0),GAMEFONT);
	b->Render("Ted Pereira",350,(int)startPos +80 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
    


	b->Render("Special Thanks:",350,(int)startPos +85 * pluser++,1.5,D3DCOLOR_XRGB(0,0,0),GAMEFONT);
	b->Render("Dave Brown",350,(int)startPos +85 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	// b->Render("Steve Hamlin",350,(int)startPos +75 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	b->Render("Ron Powell",350,(int)startPos +85 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	b->Render("Rob Martinez",350,(int)startPos +85 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	b->Render("Sean Hathaway",350,(int)startPos +85 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	b->Render("Chris Jahosky",350,(int)startPos +85 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	b->Render("Caffiene",350,(int)startPos +85 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	b->Render("Google",350,(int)startPos +85 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	// b->Render("ijji Lunia (sounds)",350,(int)startPos +75 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);
	// b->Render("Japan. Get better :(",350,(int)startPos +75 * pluser++,1.5,D3DCOLOR_XRGB(100,0,0),GAMEFONT);


	float pos = startPos + 95 * pluser++;
	if(pos <= 200)
	{
		pos = 200;
		trigger = true;

		if(timer >= 4.8f)
		{
			CGame::GetInstance()->ChangeState(CMainMenuState::GetInstance());
			CMainMenuState::GetInstance()->main_scrolling = true;

			return;
		}
	}

	CSGD_TextureManager::GetInstance()->Draw(imageID, 20, (int)pos, .7f, .7f);


}

void CCreditsState::Exit(void)
{
	CSGD_TextureManager::GetInstance()->UnloadTexture(background);

}


CCreditsState* CCreditsState::GetInstance()
{
	static CCreditsState instance;
	return &instance;
}